{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "# cpu2017数据源 贴源数据层 代码实现\n",
    "\n",
    "## 1. 下载最新的数据源"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import requests, os\n",
    "\n",
    "def download_latest_results(benchmark_name: str):\n",
    "    \"\"\"\n",
    "    下载最新的数据源\n",
    "    :param benchmark_name: 数据源名称，应当是cpu2006, cpu2006, jbb2015, jvm2008, power_ssj2008其中的一个\n",
    "    :return: 返回成功下载的文件路径名\n",
    "    \"\"\"\n",
    "    benchmark_list = [\"cpu2017\", \"cpu2006\", \"jbb2015\", \"jvm2008\", \"power_ssj2008\"]\n",
    "    assert benchmark_name in benchmark_list\n",
    "    # 根据数据源名称生成下载路径\n",
    "    download_addr = f\"https://www.spec.org/cgi-bin/osgresults?conf={benchmark_name};op=dump;format=csvdump\"\n",
    "    try:\n",
    "        response = requests.get(download_addr, stream=True)\n",
    "        response.raise_for_status()\n",
    "        # 从response的header中获得文件名，这个文件名包含了数据源名称以及下载时的日期时间\n",
    "        file_name = response.headers[\"Content-Disposition\"].split(\";\")[1].split(\"=\")[1][1:-1]\n",
    "        file_path = os.path.join(\"data\", file_name)\n",
    "        # 写入文件\n",
    "        with open(file_path, \"wb\") as f:\n",
    "            for chunk in response.iter_content(chunk_size=1048576):\n",
    "                if chunk:\n",
    "                    f.write(chunk)\n",
    "        return file_path\n",
    "    except Exception as e:\n",
    "        print(\"failed to download results\")\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 2. 获得已经下载到本地的最新数据源"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [],
   "source": [
    "def get_latest_results(benchmark_name: str, delete_old: bool = False):\n",
    "    \"\"\"\n",
    "    返回本地最新的数据源文件路径名\n",
    "    :param benchmark_name: 数据源名称，应当是cpu2006, cpu2006, jbb2015, jvm2008, power_ssj2008其中的一个\n",
    "    :param delete_old: 是否删除旧的数据源文件\n",
    "    :return: 返回最新的数据源文件路径名\n",
    "    \"\"\"\n",
    "    benchmark_list = [\"cpu2017\", \"cpu2006\", \"jbb2015\", \"jvm2008\", \"power_ssj2008\"]\n",
    "    assert benchmark_name in benchmark_list\n",
    "    all_file_path_list = os.listdir(\"data/raw\")  # 获取data文件夹下所有文件名的列表\n",
    "    benchmark_file_path_list = [i for i in all_file_path_list if i.find(benchmark_name) != -1]  # 找到属于该数据源的所有文件\n",
    "    max_time = 0  # 记录数据源文件的下载时间\n",
    "    max_time_index = 0  # 记录数据源文件的在列表中的下标\n",
    "    for index, i in enumerate(benchmark_file_path_list):\n",
    "        time = int(i.split(\"-\")[-2] + i.split(\"-\")[-1].split(\".\")[0])\n",
    "        if time > max_time:  # 保留数值最大（即下载时间最新）的数据源文件下标\n",
    "            max_time = time\n",
    "            max_time_index = index\n",
    "    latest_file_path = benchmark_file_path_list[max_time_index]  # 最新的数据源文件名称\n",
    "    if delete_old:  # 如果需要删除旧的数据源文件\n",
    "        del benchmark_file_path_list[max_time_index]\n",
    "        for i in benchmark_file_path_list:\n",
    "            os.remove(os.path.join(\"data/raw\", i))\n",
    "    return os.path.join(\"data/raw\", latest_file_path)  # 生成路径名并返回\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 3. 使用pandas读取CSV文件并整理成DataFrame"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [
    {
     "data": {
      "text/plain": "         Benchmark Hardware Vendor\\t  \\\n0         CINT2006       ACTION S.A.   \n1         CINT2006       ACTION S.A.   \n2         CINT2006       ACTION S.A.   \n3         CINT2006       ACTION S.A.   \n4         CINT2006       ACTION S.A.   \n...            ...               ...   \n48376  CFP2006rate     Wipro Limited   \n48377  CFP2006rate          YOYOtech   \n48378  CFP2006rate             Yadro   \n48379  CFP2006rate             Yadro   \n48380  CFP2006rate               ZTE   \n\n                                                  System  Result  Baseline  \\\n0      ACTINA SOLAR 110 S6 (Intel Xeon E3-1220 v3, 3....    58.7      56.9   \n1      ACTINA SOLAR 202 S6 (Intel Xeon E5-2697 v3, 2....    67.5      64.4   \n2               ACTINA SOLAR 205 S5 (Intel Xeon E5-2420)    35.8      32.8   \n3               ACTINA SOLAR 210 X5 (Intel Xeon E5-2630)    41.5      38.9   \n4      ACTINA SOLAR 210 X6 (Intel Xeon E5-2603 v4, 1....    35.4      34.4   \n...                                                  ...     ...       ...   \n48376                 Wipro NetPowerZ2243/NetPowerZ2243R   258.0     252.0   \n48377              Fi7EPOWER MLK1610 (Intel Core i7-965)    88.3      84.7   \n48378        Yadro Vesnin (2.92 GHz, 40 cores, RHEL 7.4)     0.0    1500.0   \n48379        Yadro Vesnin (3.32 GHz, 32 cores, RHEL 7.2)     0.0    1380.0   \n48380                 ATCA SBCR (Intel Xeon E5-2628L v2)   406.0     400.0   \n\n       # Cores  # Chips   # Cores Per Chip   # Threads Per Core  \\\n0            4         1                  4                   1   \n1           28         2                 14                   1   \n2           12         2                  6                   2   \n3           12         2                  6                   2   \n4           12         2                  6                   1   \n...        ...       ...                ...                 ...   \n48376       12         2                  6                   2   \n48377        4         1                  4                   2   \n48378       40         4                 10                   4   \n48379       32         4                  8                   4   \n48380       16         2                  8                   2   \n\n                              Processor   ...  HW Avail  SW Avail License  \\\n0                  Intel Xeon E3-1220 v3  ...  Sep-2014  Aug-2015    9008   \n1                  Intel Xeon E5-2697 v3  ...  Sep-2014  Aug-2015    9008   \n2                     Intel Xeon E5-2420  ...  May-2012  Feb-2012    9008   \n3                     Intel Xeon E5-2630  ...  Mar-2012  Feb-2012    9008   \n4                  Intel Xeon E5-2603 v4  ...  Mar-2016  Mar-2016    9008   \n...                                  ...  ...       ...       ...     ...   \n48376                   Intel Xeon X5670  ...  Apr-2011  May-2011     937   \n48377  Intel Core i7-965 Extreme Edition  ...  Nov-2008  Nov-2008    3772   \n48378                         IBM POWER8  ...  Dec-2017  Dec-2016    4813   \n48379                         IBM POWER8  ...  Dec-2017  Dec-2016    4813   \n48380             Intel Xeon E5-2628L v2  ...  Sep-2013  Sep-2014    3834   \n\n                    Tested By            Test Sponsor Test Date Published  \\\n0                 ACTION S.A.             ACTION S.A.  Dec-2015  Dec-2015   \n1                 ACTION S.A.             ACTION S.A.  Nov-2015  Dec-2015   \n2                 ACTION S.A.             ACTION S.A.  Oct-2012  Dec-2012   \n3                 ACTION S.A.             ACTION S.A.  Oct-2012  Dec-2012   \n4                 ACTION S.A.             ACTION S.A.  Sep-2016  Nov-2016   \n...                       ...                     ...       ...       ...   \n48376           Wipro Limited           Wipro Limited  Jun-2011  Aug-2011   \n48377  Future Publishing Ltd.  Future Publishing Ltd.  Oct-2008  Jan-2009   \n48378                   Yadro                   Yadro  Dec-2017  Mar-2018   \n48379                   Yadro                   Yadro  Dec-2017  Mar-2018   \n48380                     ZTE                     ZTE  Aug-2015  Sep-2015   \n\n       Updated                                          Disclosure Disclosures  \n0      Dec-2015  <A HREF=\"/cpu2006/results/res2015q4/cpu2006-20...         NaN  \n1      Dec-2015  <A HREF=\"/cpu2006/results/res2015q4/cpu2006-20...         NaN  \n2      Jul-2014  <A HREF=\"/cpu2006/results/res2012q4/cpu2006-20...         NaN  \n3      Jul-2014  <A HREF=\"/cpu2006/results/res2012q4/cpu2006-20...         NaN  \n4      Nov-2016  <A HREF=\"/cpu2006/results/res2016q4/cpu2006-20...         NaN  \n...         ...                                                ...         ...  \n48376  Jul-2014  <A HREF=\"/cpu2006/results/res2011q3/cpu2006-20...         NaN  \n48377  Jul-2014  <A HREF=\"/cpu2006/results/res2009q1/cpu2006-20...         NaN  \n48378  Mar-2018  <A HREF=\"/cpu2006/results/res2018q1/cpu2006-20...         NaN  \n48379  Mar-2018  <A HREF=\"/cpu2006/results/res2018q1/cpu2006-20...         NaN  \n48380  Sep-2015  <A HREF=\"/cpu2006/results/res2015q3/cpu2006-20...         NaN  \n\n[48381 rows x 34 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Benchmark</th>\n      <th>Hardware Vendor\\t</th>\n      <th>System</th>\n      <th>Result</th>\n      <th>Baseline</th>\n      <th># Cores</th>\n      <th># Chips</th>\n      <th># Cores Per Chip</th>\n      <th># Threads Per Core</th>\n      <th>Processor</th>\n      <th>...</th>\n      <th>HW Avail</th>\n      <th>SW Avail</th>\n      <th>License</th>\n      <th>Tested By</th>\n      <th>Test Sponsor</th>\n      <th>Test Date</th>\n      <th>Published</th>\n      <th>Updated</th>\n      <th>Disclosure</th>\n      <th>Disclosures</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>CINT2006</td>\n      <td>ACTION S.A.</td>\n      <td>ACTINA SOLAR 110 S6 (Intel Xeon E3-1220 v3, 3....</td>\n      <td>58.7</td>\n      <td>56.9</td>\n      <td>4</td>\n      <td>1</td>\n      <td>4</td>\n      <td>1</td>\n      <td>Intel Xeon E3-1220 v3</td>\n      <td>...</td>\n      <td>Sep-2014</td>\n      <td>Aug-2015</td>\n      <td>9008</td>\n      <td>ACTION S.A.</td>\n      <td>ACTION S.A.</td>\n      <td>Dec-2015</td>\n      <td>Dec-2015</td>\n      <td>Dec-2015</td>\n      <td>&lt;A HREF=\"/cpu2006/results/res2015q4/cpu2006-20...</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>CINT2006</td>\n      <td>ACTION S.A.</td>\n      <td>ACTINA SOLAR 202 S6 (Intel Xeon E5-2697 v3, 2....</td>\n      <td>67.5</td>\n      <td>64.4</td>\n      <td>28</td>\n      <td>2</td>\n      <td>14</td>\n      <td>1</td>\n      <td>Intel Xeon E5-2697 v3</td>\n      <td>...</td>\n      <td>Sep-2014</td>\n      <td>Aug-2015</td>\n      <td>9008</td>\n      <td>ACTION S.A.</td>\n      <td>ACTION S.A.</td>\n      <td>Nov-2015</td>\n      <td>Dec-2015</td>\n      <td>Dec-2015</td>\n      <td>&lt;A HREF=\"/cpu2006/results/res2015q4/cpu2006-20...</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>CINT2006</td>\n      <td>ACTION S.A.</td>\n      <td>ACTINA SOLAR 205 S5 (Intel Xeon E5-2420)</td>\n      <td>35.8</td>\n      <td>32.8</td>\n      <td>12</td>\n      <td>2</td>\n      <td>6</td>\n      <td>2</td>\n      <td>Intel Xeon E5-2420</td>\n      <td>...</td>\n      <td>May-2012</td>\n      <td>Feb-2012</td>\n      <td>9008</td>\n      <td>ACTION S.A.</td>\n      <td>ACTION S.A.</td>\n      <td>Oct-2012</td>\n      <td>Dec-2012</td>\n      <td>Jul-2014</td>\n      <td>&lt;A HREF=\"/cpu2006/results/res2012q4/cpu2006-20...</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>CINT2006</td>\n      <td>ACTION S.A.</td>\n      <td>ACTINA SOLAR 210 X5 (Intel Xeon E5-2630)</td>\n      <td>41.5</td>\n      <td>38.9</td>\n      <td>12</td>\n      <td>2</td>\n      <td>6</td>\n      <td>2</td>\n      <td>Intel Xeon E5-2630</td>\n      <td>...</td>\n      <td>Mar-2012</td>\n      <td>Feb-2012</td>\n      <td>9008</td>\n      <td>ACTION S.A.</td>\n      <td>ACTION S.A.</td>\n      <td>Oct-2012</td>\n      <td>Dec-2012</td>\n      <td>Jul-2014</td>\n      <td>&lt;A HREF=\"/cpu2006/results/res2012q4/cpu2006-20...</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>CINT2006</td>\n      <td>ACTION S.A.</td>\n      <td>ACTINA SOLAR 210 X6 (Intel Xeon E5-2603 v4, 1....</td>\n      <td>35.4</td>\n      <td>34.4</td>\n      <td>12</td>\n      <td>2</td>\n      <td>6</td>\n      <td>1</td>\n      <td>Intel Xeon E5-2603 v4</td>\n      <td>...</td>\n      <td>Mar-2016</td>\n      <td>Mar-2016</td>\n      <td>9008</td>\n      <td>ACTION S.A.</td>\n      <td>ACTION S.A.</td>\n      <td>Sep-2016</td>\n      <td>Nov-2016</td>\n      <td>Nov-2016</td>\n      <td>&lt;A HREF=\"/cpu2006/results/res2016q4/cpu2006-20...</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>48376</th>\n      <td>CFP2006rate</td>\n      <td>Wipro Limited</td>\n      <td>Wipro NetPowerZ2243/NetPowerZ2243R</td>\n      <td>258.0</td>\n      <td>252.0</td>\n      <td>12</td>\n      <td>2</td>\n      <td>6</td>\n      <td>2</td>\n      <td>Intel Xeon X5670</td>\n      <td>...</td>\n      <td>Apr-2011</td>\n      <td>May-2011</td>\n      <td>937</td>\n      <td>Wipro Limited</td>\n      <td>Wipro Limited</td>\n      <td>Jun-2011</td>\n      <td>Aug-2011</td>\n      <td>Jul-2014</td>\n      <td>&lt;A HREF=\"/cpu2006/results/res2011q3/cpu2006-20...</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>48377</th>\n      <td>CFP2006rate</td>\n      <td>YOYOtech</td>\n      <td>Fi7EPOWER MLK1610 (Intel Core i7-965)</td>\n      <td>88.3</td>\n      <td>84.7</td>\n      <td>4</td>\n      <td>1</td>\n      <td>4</td>\n      <td>2</td>\n      <td>Intel Core i7-965 Extreme Edition</td>\n      <td>...</td>\n      <td>Nov-2008</td>\n      <td>Nov-2008</td>\n      <td>3772</td>\n      <td>Future Publishing Ltd.</td>\n      <td>Future Publishing Ltd.</td>\n      <td>Oct-2008</td>\n      <td>Jan-2009</td>\n      <td>Jul-2014</td>\n      <td>&lt;A HREF=\"/cpu2006/results/res2009q1/cpu2006-20...</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>48378</th>\n      <td>CFP2006rate</td>\n      <td>Yadro</td>\n      <td>Yadro Vesnin (2.92 GHz, 40 cores, RHEL 7.4)</td>\n      <td>0.0</td>\n      <td>1500.0</td>\n      <td>40</td>\n      <td>4</td>\n      <td>10</td>\n      <td>4</td>\n      <td>IBM POWER8</td>\n      <td>...</td>\n      <td>Dec-2017</td>\n      <td>Dec-2016</td>\n      <td>4813</td>\n      <td>Yadro</td>\n      <td>Yadro</td>\n      <td>Dec-2017</td>\n      <td>Mar-2018</td>\n      <td>Mar-2018</td>\n      <td>&lt;A HREF=\"/cpu2006/results/res2018q1/cpu2006-20...</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>48379</th>\n      <td>CFP2006rate</td>\n      <td>Yadro</td>\n      <td>Yadro Vesnin (3.32 GHz, 32 cores, RHEL 7.2)</td>\n      <td>0.0</td>\n      <td>1380.0</td>\n      <td>32</td>\n      <td>4</td>\n      <td>8</td>\n      <td>4</td>\n      <td>IBM POWER8</td>\n      <td>...</td>\n      <td>Dec-2017</td>\n      <td>Dec-2016</td>\n      <td>4813</td>\n      <td>Yadro</td>\n      <td>Yadro</td>\n      <td>Dec-2017</td>\n      <td>Mar-2018</td>\n      <td>Mar-2018</td>\n      <td>&lt;A HREF=\"/cpu2006/results/res2018q1/cpu2006-20...</td>\n      <td>NaN</td>\n    </tr>\n    <tr>\n      <th>48380</th>\n      <td>CFP2006rate</td>\n      <td>ZTE</td>\n      <td>ATCA SBCR (Intel Xeon E5-2628L v2)</td>\n      <td>406.0</td>\n      <td>400.0</td>\n      <td>16</td>\n      <td>2</td>\n      <td>8</td>\n      <td>2</td>\n      <td>Intel Xeon E5-2628L v2</td>\n      <td>...</td>\n      <td>Sep-2013</td>\n      <td>Sep-2014</td>\n      <td>3834</td>\n      <td>ZTE</td>\n      <td>ZTE</td>\n      <td>Aug-2015</td>\n      <td>Sep-2015</td>\n      <td>Sep-2015</td>\n      <td>&lt;A HREF=\"/cpu2006/results/res2015q3/cpu2006-20...</td>\n      <td>NaN</td>\n    </tr>\n  </tbody>\n</table>\n<p>48381 rows × 34 columns</p>\n</div>"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "cpu2006_data = pd.read_csv(get_latest_results(benchmark_name=\"cpu2006\"))\n",
    "cpu2006_data"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "## 4. 贴源数据层的实现：从数据源中抽取相关的属性并聚合\n",
    "\n",
    "尝试对数据进行一些处理，例如对同一个生产厂家的机器做一个聚合，从生产厂家的角度考察机器的Java性能"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%% md\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 4.1 抽取感兴趣的属性\n",
    "\n",
    "感兴趣的属性：\n",
    "- Hardware Vendor机器生产公司\n",
    "- System系统型号\n",
    "- Result得分\n",
    "- \\# Cores核心数\n",
    "- \\# Chips中间计算需要\n",
    "- Processor处理器型号【是统一的数据主体，合并数据时以该属性作为准则】\n",
    "- Processor MHz CPU频率\n",
    "- 各级Cache容量：1st Level Cache, 2nd Level Cache, 3rd Level Cache, Other Cache\n",
    "- Memory存储大小\n",
    "- Updated最后分数记录时间\n",
    "- Disclosure详细结果报告的链接\n",
    "\n",
    "#### 主要处理的内容为\n",
    "将cpu2017的属性名向jvm2008靠拢，更新提取的属性名。\n",
    "\\# 更新部分属性名 [\"Company\", \"System\", \"Result\", \"# cores\", \"Processor\", \"CPU Speed(MHz)\", \"1st Cache per core(KB)\",\n",
    "\\# \"2nd Cache per core(KB)\", \"3rd Cache per chip(MB)\", \"Other Cache per chip(MB)\", \"Memory(GB)\", \"Updated\",\n",
    "\\# \"Report Link\"]"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "data": {
      "text/plain": "             Company                                             System  \\\n0        ACTION S.A.  ACTINA SOLAR 110 S6 (Intel Xeon E3-1220 v3, 3....   \n1        ACTION S.A.  ACTINA SOLAR 202 S6 (Intel Xeon E5-2697 v3, 2....   \n2        ACTION S.A.           ACTINA SOLAR 205 S5 (Intel Xeon E5-2420)   \n3        ACTION S.A.           ACTINA SOLAR 210 X5 (Intel Xeon E5-2630)   \n4        ACTION S.A.  ACTINA SOLAR 210 X6 (Intel Xeon E5-2603 v4, 1....   \n...              ...                                                ...   \n48376  Wipro Limited                 Wipro NetPowerZ2243/NetPowerZ2243R   \n48377       YOYOtech              Fi7EPOWER MLK1610 (Intel Core i7-965)   \n48378          Yadro        Yadro Vesnin (2.92 GHz, 40 cores, RHEL 7.4)   \n48379          Yadro        Yadro Vesnin (3.32 GHz, 32 cores, RHEL 7.2)   \n48380            ZTE                 ATCA SBCR (Intel Xeon E5-2628L v2)   \n\n       Result  # cores  # chips                          Processor  \\\n0        58.7        4        1              Intel Xeon E3-1220 v3   \n1        67.5       28        2              Intel Xeon E5-2697 v3   \n2        35.8       12        2                 Intel Xeon E5-2420   \n3        41.5       12        2                 Intel Xeon E5-2630   \n4        35.4       12        2              Intel Xeon E5-2603 v4   \n...       ...      ...      ...                                ...   \n48376   258.0       12        2                   Intel Xeon X5670   \n48377    88.3        4        1  Intel Core i7-965 Extreme Edition   \n48378     0.0       40        4                         IBM POWER8   \n48379     0.0       32        4                         IBM POWER8   \n48380   406.0       16        2             Intel Xeon E5-2628L v2   \n\n       CPU Speed(MHz)              1st Cache per core(KB)  \\\n0                3100  32 KB I + 32 KB D on chip per core   \n1                2600  32 KB I + 32 KB D on chip per core   \n2                1900  32 KB I + 32 KB D on chip per core   \n3                2300  32 KB I + 32 KB D on chip per core   \n4                1700  32 KB I + 32 KB D on chip per core   \n...               ...                                 ...   \n48376            2933  32 KB I + 32 KB D on chip per core   \n48377            3733  32 KB I + 32 KB D on chip per core   \n48378            2926  32 KB I + 64 KB D on chip per core   \n48379            3325  32 KB I + 64 KB D on chip per core   \n48380            1900  32 KB I + 32 KB D on chip per core   \n\n            2nd Cache per core(KB)      3rd Cache per chip(MB)  \\\n0      256 KB I+D on chip per core   8 MB I+D on chip per chip   \n1      256 KB I+D on chip per core  35 MB I+D on chip per chip   \n2      256 KB I+D on chip per core  15 MB I+D on chip per chip   \n3      256 KB I+D on chip per core  15 MB I+D on chip per chip   \n4      256 KB I+D on chip per core  15 MB I+D on chip per chip   \n...                            ...                         ...   \n48376  256 KB I+D on chip per core  12 MB I+D on chip per chip   \n48377  256 KB I+D on chip per core   8 MB I+D on chip per chip   \n48378  512 KB I+D on chip per core   8 MB I+D on chip per core   \n48379  512 KB I+D on chip per core   8 MB I+D on chip per core   \n48380  256 KB I+D on chip per core  20 MB I+D on chip per chip   \n\n             Other Cache per chip(MB)  \\\n0                                None   \n1                                None   \n2                                None   \n3                                None   \n4                                None   \n...                               ...   \n48376                            None   \n48377                            None   \n48378  16 MB I+D off chip per 8 DIMMs   \n48379  16 MB I+D off chip per 8 DIMMs   \n48380                            None   \n\n                                              Memory(GB)   Updated  \\\n0               32 GB (4 x 8 GB 2Rx8 PC3-12800E-11, ECC)  Dec-2015   \n1      256 GB (16 x 16 GB 2Rx4 PC4-2400P-R, running a...  Dec-2015   \n2      96 GB (6 x 16 GB 2Rx4 PC3-12800R-11, ECC, runn...  Jul-2014   \n3             128 GB (16 x 8 GB 2Rx4 PC3-12800R-11, ECC)  Jul-2014   \n4      256 GB (16 x 16 GB 2Rx4 PC4-2133P-R, running a...  Nov-2016   \n...                                                  ...       ...   \n48376           96 GB (12 x 8 GB 2Rx4 PC3-10600R-9, ECC)  Jul-2014   \n48377  9 GB (3x 2GB and 3x 1GB Corsair DDR3-1066, 9-9...  Jul-2014   \n48378  4 TB (128 x 32 GB 2Rx4 PC4 - 2400T, running at...  Mar-2018   \n48379  8 TB (128 x 64 GB 4Rx4 PC4 - 2400T, running at...  Mar-2018   \n48380           128 GB (8 x 16 GB 2Rx4 PC3-10600R-9 ECC)  Sep-2015   \n\n                                             Report Link  \n0      <A HREF=\"/cpu2006/results/res2015q4/cpu2006-20...  \n1      <A HREF=\"/cpu2006/results/res2015q4/cpu2006-20...  \n2      <A HREF=\"/cpu2006/results/res2012q4/cpu2006-20...  \n3      <A HREF=\"/cpu2006/results/res2012q4/cpu2006-20...  \n4      <A HREF=\"/cpu2006/results/res2016q4/cpu2006-20...  \n...                                                  ...  \n48376  <A HREF=\"/cpu2006/results/res2011q3/cpu2006-20...  \n48377  <A HREF=\"/cpu2006/results/res2009q1/cpu2006-20...  \n48378  <A HREF=\"/cpu2006/results/res2018q1/cpu2006-20...  \n48379  <A HREF=\"/cpu2006/results/res2018q1/cpu2006-20...  \n48380  <A HREF=\"/cpu2006/results/res2015q3/cpu2006-20...  \n\n[48381 rows x 14 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Company</th>\n      <th>System</th>\n      <th>Result</th>\n      <th># cores</th>\n      <th># chips</th>\n      <th>Processor</th>\n      <th>CPU Speed(MHz)</th>\n      <th>1st Cache per core(KB)</th>\n      <th>2nd Cache per core(KB)</th>\n      <th>3rd Cache per chip(MB)</th>\n      <th>Other Cache per chip(MB)</th>\n      <th>Memory(GB)</th>\n      <th>Updated</th>\n      <th>Report Link</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>ACTION S.A.</td>\n      <td>ACTINA SOLAR 110 S6 (Intel Xeon E3-1220 v3, 3....</td>\n      <td>58.7</td>\n      <td>4</td>\n      <td>1</td>\n      <td>Intel Xeon E3-1220 v3</td>\n      <td>3100</td>\n      <td>32 KB I + 32 KB D on chip per core</td>\n      <td>256 KB I+D on chip per core</td>\n      <td>8 MB I+D on chip per chip</td>\n      <td>None</td>\n      <td>32 GB (4 x 8 GB 2Rx8 PC3-12800E-11, ECC)</td>\n      <td>Dec-2015</td>\n      <td>&lt;A HREF=\"/cpu2006/results/res2015q4/cpu2006-20...</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>ACTION S.A.</td>\n      <td>ACTINA SOLAR 202 S6 (Intel Xeon E5-2697 v3, 2....</td>\n      <td>67.5</td>\n      <td>28</td>\n      <td>2</td>\n      <td>Intel Xeon E5-2697 v3</td>\n      <td>2600</td>\n      <td>32 KB I + 32 KB D on chip per core</td>\n      <td>256 KB I+D on chip per core</td>\n      <td>35 MB I+D on chip per chip</td>\n      <td>None</td>\n      <td>256 GB (16 x 16 GB 2Rx4 PC4-2400P-R, running a...</td>\n      <td>Dec-2015</td>\n      <td>&lt;A HREF=\"/cpu2006/results/res2015q4/cpu2006-20...</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>ACTION S.A.</td>\n      <td>ACTINA SOLAR 205 S5 (Intel Xeon E5-2420)</td>\n      <td>35.8</td>\n      <td>12</td>\n      <td>2</td>\n      <td>Intel Xeon E5-2420</td>\n      <td>1900</td>\n      <td>32 KB I + 32 KB D on chip per core</td>\n      <td>256 KB I+D on chip per core</td>\n      <td>15 MB I+D on chip per chip</td>\n      <td>None</td>\n      <td>96 GB (6 x 16 GB 2Rx4 PC3-12800R-11, ECC, runn...</td>\n      <td>Jul-2014</td>\n      <td>&lt;A HREF=\"/cpu2006/results/res2012q4/cpu2006-20...</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>ACTION S.A.</td>\n      <td>ACTINA SOLAR 210 X5 (Intel Xeon E5-2630)</td>\n      <td>41.5</td>\n      <td>12</td>\n      <td>2</td>\n      <td>Intel Xeon E5-2630</td>\n      <td>2300</td>\n      <td>32 KB I + 32 KB D on chip per core</td>\n      <td>256 KB I+D on chip per core</td>\n      <td>15 MB I+D on chip per chip</td>\n      <td>None</td>\n      <td>128 GB (16 x 8 GB 2Rx4 PC3-12800R-11, ECC)</td>\n      <td>Jul-2014</td>\n      <td>&lt;A HREF=\"/cpu2006/results/res2012q4/cpu2006-20...</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>ACTION S.A.</td>\n      <td>ACTINA SOLAR 210 X6 (Intel Xeon E5-2603 v4, 1....</td>\n      <td>35.4</td>\n      <td>12</td>\n      <td>2</td>\n      <td>Intel Xeon E5-2603 v4</td>\n      <td>1700</td>\n      <td>32 KB I + 32 KB D on chip per core</td>\n      <td>256 KB I+D on chip per core</td>\n      <td>15 MB I+D on chip per chip</td>\n      <td>None</td>\n      <td>256 GB (16 x 16 GB 2Rx4 PC4-2133P-R, running a...</td>\n      <td>Nov-2016</td>\n      <td>&lt;A HREF=\"/cpu2006/results/res2016q4/cpu2006-20...</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>48376</th>\n      <td>Wipro Limited</td>\n      <td>Wipro NetPowerZ2243/NetPowerZ2243R</td>\n      <td>258.0</td>\n      <td>12</td>\n      <td>2</td>\n      <td>Intel Xeon X5670</td>\n      <td>2933</td>\n      <td>32 KB I + 32 KB D on chip per core</td>\n      <td>256 KB I+D on chip per core</td>\n      <td>12 MB I+D on chip per chip</td>\n      <td>None</td>\n      <td>96 GB (12 x 8 GB 2Rx4 PC3-10600R-9, ECC)</td>\n      <td>Jul-2014</td>\n      <td>&lt;A HREF=\"/cpu2006/results/res2011q3/cpu2006-20...</td>\n    </tr>\n    <tr>\n      <th>48377</th>\n      <td>YOYOtech</td>\n      <td>Fi7EPOWER MLK1610 (Intel Core i7-965)</td>\n      <td>88.3</td>\n      <td>4</td>\n      <td>1</td>\n      <td>Intel Core i7-965 Extreme Edition</td>\n      <td>3733</td>\n      <td>32 KB I + 32 KB D on chip per core</td>\n      <td>256 KB I+D on chip per core</td>\n      <td>8 MB I+D on chip per chip</td>\n      <td>None</td>\n      <td>9 GB (3x 2GB and 3x 1GB Corsair DDR3-1066, 9-9...</td>\n      <td>Jul-2014</td>\n      <td>&lt;A HREF=\"/cpu2006/results/res2009q1/cpu2006-20...</td>\n    </tr>\n    <tr>\n      <th>48378</th>\n      <td>Yadro</td>\n      <td>Yadro Vesnin (2.92 GHz, 40 cores, RHEL 7.4)</td>\n      <td>0.0</td>\n      <td>40</td>\n      <td>4</td>\n      <td>IBM POWER8</td>\n      <td>2926</td>\n      <td>32 KB I + 64 KB D on chip per core</td>\n      <td>512 KB I+D on chip per core</td>\n      <td>8 MB I+D on chip per core</td>\n      <td>16 MB I+D off chip per 8 DIMMs</td>\n      <td>4 TB (128 x 32 GB 2Rx4 PC4 - 2400T, running at...</td>\n      <td>Mar-2018</td>\n      <td>&lt;A HREF=\"/cpu2006/results/res2018q1/cpu2006-20...</td>\n    </tr>\n    <tr>\n      <th>48379</th>\n      <td>Yadro</td>\n      <td>Yadro Vesnin (3.32 GHz, 32 cores, RHEL 7.2)</td>\n      <td>0.0</td>\n      <td>32</td>\n      <td>4</td>\n      <td>IBM POWER8</td>\n      <td>3325</td>\n      <td>32 KB I + 64 KB D on chip per core</td>\n      <td>512 KB I+D on chip per core</td>\n      <td>8 MB I+D on chip per core</td>\n      <td>16 MB I+D off chip per 8 DIMMs</td>\n      <td>8 TB (128 x 64 GB 4Rx4 PC4 - 2400T, running at...</td>\n      <td>Mar-2018</td>\n      <td>&lt;A HREF=\"/cpu2006/results/res2018q1/cpu2006-20...</td>\n    </tr>\n    <tr>\n      <th>48380</th>\n      <td>ZTE</td>\n      <td>ATCA SBCR (Intel Xeon E5-2628L v2)</td>\n      <td>406.0</td>\n      <td>16</td>\n      <td>2</td>\n      <td>Intel Xeon E5-2628L v2</td>\n      <td>1900</td>\n      <td>32 KB I + 32 KB D on chip per core</td>\n      <td>256 KB I+D on chip per core</td>\n      <td>20 MB I+D on chip per chip</td>\n      <td>None</td>\n      <td>128 GB (8 x 16 GB 2Rx4 PC3-10600R-9 ECC)</td>\n      <td>Sep-2015</td>\n      <td>&lt;A HREF=\"/cpu2006/results/res2015q3/cpu2006-20...</td>\n    </tr>\n  </tbody>\n</table>\n<p>48381 rows × 14 columns</p>\n</div>"
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# cpu2006数据源，感兴趣的属性\n",
    "ods_cpu2006_col = [\"Hardware Vendor\t\", \"System\", \"Result\", \"# Cores\", \"# Chips \", \"Processor \", \"Processor MHz\",\n",
    "                   \"1st Level Cache\", \"2nd Level Cache\", \"3rd Level Cache\", \"Other Cache\", \"Memory\", \"Updated \",\n",
    "                   \"Disclosure\"]\n",
    "\n",
    "# 抽取相关属性，构成DataFrame，前缀为ods表明为贴源数据层（其中# cores per chip为中间数据，数据清洗完成后应当删去）\n",
    "ods_cpu2006_data = pd.read_csv(get_latest_results(benchmark_name=\"cpu2006\"), usecols=ods_cpu2006_col)\n",
    "\n",
    "# 更新部分属性名 [\"Company\", \"System\", \"Result\", \"# cores\", \"Processor\", \"CPU Speed(MHz)\", \"1st Cache per core(KB)\",\n",
    "# \"2nd Cache per core(KB)\", \"3rd Cache per chip(MB)\", \"Other Cache per chip(MB)\", \"Memory(GB)\", \"Updated\",\n",
    "# \"Report Link\"]\n",
    "ods_cpu2006_data = ods_cpu2006_data.rename(columns={\"Hardware Vendor\t\": \"Company\",\n",
    "                                                    \"Base Result\": \"Result\",\n",
    "                                                    \"# Cores\": \"# cores\",\n",
    "                                                    \"# Chips \": \"# chips\",\n",
    "                                                    \"Processor \": \"Processor\",\n",
    "                                                    \"Processor MHz\": \"CPU Speed(MHz)\",\n",
    "                                                    \"1st Level Cache\": \"1st Cache per core(KB)\",\n",
    "                                                    \"2nd Level Cache\": \"2nd Cache per core(KB)\",\n",
    "                                                    \"3rd Level Cache\": \"3rd Cache per chip(MB)\",\n",
    "                                                    \"Other Cache\": \"Other Cache per chip(MB)\",\n",
    "                                                    \"Memory\": \"Memory(GB)\",\n",
    "                                                    \"Updated \": \"Updated\",\n",
    "                                                    \"Disclosure\": \"Report Link\"})\n",
    "ods_cpu2006_data\n",
    "# print(ods_cpu2006_data)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "### 4.2 数据转换和清洗\n",
    "\n",
    "引入需要的库，后续对每一个属性的值，写出一个转换函数，即原始值X到转换后的值Y的函数，这个函数可以套用到DataFrame的map方法或者apply方法，用于批量操作"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [],
   "source": [
    "import re\n",
    "from typing import Union"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "\n",
    "#### 1. Company属性\n",
    "\n",
    "1. 例如“Sun Microsystems”和“Sun Microsystems, Inc.”，应当统一为不含逗号的\n",
    "2. 对于“NTT System S. A.”和“NTT System S.A.”，遵循少数服从多数的原则将“NTT System S. A.”修改为“NTT System S.A.”\n",
    "3. 其余的缩写，例如“Inc.”则不加以处理"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "outputs": [],
   "source": [
    "def company_rule(x: str) -> str:\n",
    "    \"\"\"\n",
    "    对Company这一列数据的处理操作，用于DataFrame的map方法\n",
    "    :param x: Company属性的值\n",
    "    :return: 处理后的值\n",
    "    \"\"\"\n",
    "    y = x.replace(\",\", \"\")    # 去除逗号\n",
    "    y = re.sub(r\"NTT System S. A.\", \"NTT System S.A.\", y)    # 正则表达式替换：\\b匹配单词边界，$匹配字符串末尾\n",
    "\n",
    "    return y"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "\n",
    "#### 2. System属性：不处理\n",
    "\n",
    "#### 3. Result属性：不处理\n",
    "\n",
    "#### 4. \\# cores属性：不处理\n",
    "\n",
    "#### 5. Processor属性：未处理\n",
    "\n",
    "应当向cpu2017数据源的Processor属性的取值看齐"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "#### 6. CPU Speed属性：不处理"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "#### 7. Cache相关属性\n",
    "\n",
    "1. 1st Cache属性，单位为KB，统一为per core，有2种情况：\n",
    "    1. \\[case\\] \"redacted\"\n",
    "        - \\[case1\\] \"redacted\"\n",
    "            返回 \"0\"\n",
    "    2. \\[case\\] \".*I\\s*+.*\" (有加号)\n",
    "        1. \\[case\\] 有“micro”\n",
    "            - \\[case2\\] \"KB\" \"per core\" eg. 12 K micro-ops I + 16 KB D on chip per core\n",
    "                利用正则匹配，取出数字，整理为“XXK micro-ops(I)+XXKB(D)”\n",
    "            - \\[case3\\] \"KB\" “per chip” eg. 12 K micro-ops I + 16 KB D on chip per chip\n",
    "                利用正则匹配，取出数字，借助“# chips”和“# cores”两个属性值，转换成per core，整理为“XXK micro-ops(I)+XXKB(D)”\n",
    "        2. \\[case\\] 无“micro”有“per core”\n",
    "            - \\[case4\\] \"KB\" “per core” eg. 32 KB I + 32 KB D on chip per core\n",
    "                利用正则匹配，取出数字，整理为“XXKB(I)+XXKB(D)”\n",
    "        3. \\[case\\] 无“micro”有“per chip”\n",
    "            - \\[case4\\] \"KB\" “per chip” eg. 16 KB I + 16 KB D on chip per chip\n",
    "                利用正则匹配，取出数字，借助“# chips”和“# cores”两个属性值，转换成per core，整理为“XXKB(I)+XXKB(D)”\n",
    "    3. \\[case\\] \".*I.*\" (没加号)\n",
    "        - \\[case5\\] \"KB\" I为“per chip” D为\"per core\" eg. 192 KB I on chip per chip, 96 KB I shared / 2 cores; 16 KB D on chip per core\n",
    "            利用正则匹配，取出数字，对于取到的第一个数字，不做处理；对于取到的第二个数字，借助“# chips”和“# cores”两个属性值，转换成per core，整理为“XXKB(I)+XXKB(D)”\n",
    "2. 2nd Cache属性，单位为KB，统一为per core的大小，有多种情况：\n",
    "    1. \\[case\\] \".*I+D.*\"\n",
    "       1. \\[case\\] “per core”\n",
    "            - \\[case1\\] “KB” eg. 256 KB I+D on chip per core\n",
    "                利用正则匹配，取出数字，整理为“XXKB(I+D)”\n",
    "            - \\[case2\\] \"MB\" eg. 1 MB I+D on chip per core\n",
    "                利用正则匹配，取出数字，乘以1024，转化为KB，整理为“XXKB(I+D)”\n",
    "       2. \\[case\\] “per two cores”\n",
    "            - \\[case3\\] \"MB\" eg. 1 MB I+D on chip per two cores\n",
    "                利用正则匹配，取出数字，乘以1024，转化为KB，除以2，转成per core，整理为“XXKB(I+D)”\n",
    "       3. \\[case\\] “per chip”\n",
    "            - \\[case4\\] \"KB\" eg. 1920 KB I+D on chip per chip\n",
    "                利用正则匹配，取出数字，借助“# chips”和“# cores”两个属性值，转换成per core，整理为“XXKB(I+D)”\n",
    "            - \\[case5\\] \"MB\" eg. 2 MB I+D on chip per chip\n",
    "                利用正则匹配，取出数字，乘以1024，借助“# chips”和“# cores”两个属性值，转换成per core，整理为“XXKB(I+D)”\n",
    "    2. \\[case\\] \".*I.*;.*D.*\"\n",
    "        - \\[case6\\] “per chip” “MB” eg. 2 MB I on chip per chip (256 KB / 4 cores); 4 MB D on chip per chip (256 KB / 2 cores)\n",
    "            利用正则匹配，取出数字，乘以1024，借助“# chips”和“# cores”两个属性值，转换成per core，整理为“XXKB(I)+XXKB(D)”\n",
    "    3. \\[case\\] \".*I\\s*+.*\"\n",
    "        - \\[case7\\] 第一个数字“MB” 第二个数字“KB” “per core”  eg. 1 MB I + 256 KB D on chip per core\n",
    "            利用正则匹配，取出数字，第一个数字，乘以1024，第二个数字不做处理，整理为“XXKB(I)+XXKB(D)”\n",
    "        - \\[case8\\] “KB” “per core”  eg.  512 KB I + 256 KB D on chip per core\n",
    "            利用正则匹配，取出数字，整理为“XXKB(I)+XXKB(D)”\n",
    "    4. \\[case\\] \"redacted\"\n",
    "        - \\[case9\\] \"redacted\"\n",
    "            返回 \"0\"\n",
    "3. 3rd Cache属性, 单位为MB，统一为per chip的大小，有多种情况：\n",
    "    1. \\[case\\] \".*I+D.*\"\n",
    "        1. \\[case\\] 含“per core” “MB”\n",
    "            - \\[case1\\] “MB” “on chip per core” eg. 8 MB I+D on chip per core\n",
    "                利用正则匹配，取出数字，借助“# chips”和“# cores”两个属性值，转换成per chip，整理为“XXMB”\n",
    "        2. \\[case\\] “per chip” “MB”\n",
    "            - \\[case2\\] “KB” “on chip per chip” eg. 38400 KB I+D on chip per chip\n",
    "                利用正则匹配，取出数字，除以1024，整理为“XXMB”\n",
    "            - \\[case3\\] “MB” “on chip per chip” eg. 40 MB I+D on chip per chip\n",
    "                利用正则匹配，取出数字，整理为“XXMB”\n",
    "    2. \\[case\\] \"redacted\" / \"None\"\n",
    "        - \\[case4\\] \"redacted\"\n",
    "            返回 \"0\"\n",
    "        - \\[case5\\] \"None\"\n",
    "            返回 \"0\"\n",
    "4. Other Cache属性\n",
    "    - \\[case5\\] “None”\n",
    "        返回 \"0\"\n",
    "    - \\[case6\\] eg. 60 GB I+D off chip per system\n",
    "        利用正则匹配，取出数字，除以”# chips“，整理为“XXMB”\n",
    "    - \\[case7\\] eg. 16 MB I+D off chip per 8 DIMMs\n",
    "        利用正则匹配，取出数字，整理为“XXMB”"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "outputs": [],
   "source": [
    "# 4.2.7 Cache\n",
    "# 4.2.7.1 1st Cache\n",
    "def first_cache_rule(line: pd.Series) -> str:\n",
    "    \"\"\"\n",
    "    对1st Cache这一列数据的处理操作，用于DataFrame的apply方法（需要用到其他属性的值）\n",
    "    :param x: DataFrame的一行，类型是pd.Series\n",
    "    :return: 处理后的1st Cache per core(KB)值\n",
    "    \"\"\"\n",
    "    x = line[\"1st Cache per core(KB)\"]\n",
    "    cores_num = line[\"# cores\"]\n",
    "    chips_num = line[\"# chips\"]\n",
    "    if x.find(\"redacted\") != -1:\n",
    "        return \"0\"\n",
    "    elif x.find(\"I +\") != -1:\n",
    "        if x.find(\"micro\") != -1:\n",
    "            if x.find(\"per core\") != -1:  #eg. 12 K micro-ops I + 16 KB D on chip per core\n",
    "                search_obj = re.match(r\"(\\d+)\\s*K micro-ops\\s*I\\s*\\+\\s*(\\d+)\\s*KB\\s*D\", x)\n",
    "                l1i_kb = search_obj.group(1)\n",
    "                l1d_kb = search_obj.group(2)\n",
    "                return f\"{l1i_kb}KB(I)+{l1d_kb}KB(D)\"\n",
    "            else:  #eg. 12 K micro-ops I + 16 KB D on chip per chip\n",
    "                search_obj = re.match(r\"(\\d+)\\s*K micro-ops\\s*I\\s*\\+\\s*(\\d+)\\s*KB\\s*D\", x)\n",
    "                l1i_kb = int(int(search_obj.group(1)) * chips_num / float(cores_num))\n",
    "                l1d_kb = int(int(search_obj.group(2)) * chips_num / float(cores_num))\n",
    "                return f\"{l1i_kb}KB(I)+{l1d_kb}KB(D)\"\n",
    "        elif x.find(\"per core\") != -1:  #eg. 32 KB I + 32 KB D on chip per core\n",
    "            # 说明：(group1: 1个以上数字)+可能有空格+'KB'+可能有空格+I'+可能有空格+'+'+可能有空格+(group2: 1个以上数字)+可能有空格+'KB'+可能有空格+'D'\n",
    "            search_obj = re.match(r\"(\\d+)\\s*KB\\s*I\\s*\\+\\s*(\\d+)\\s*KB\\s*D\", x)\n",
    "            l1i_kb = search_obj.group(1)\n",
    "            l1d_kb = search_obj.group(2)\n",
    "            return f\"{l1i_kb}KB(I)+{l1d_kb}KB(D)\"\n",
    "        else:  #eg. 16 KB I + 16 KB D on chip per chip\n",
    "            # 说明：(group1: 1个以上数字)+可能有空格+'KB'+可能有空格+I'+可能有空格+'+'+可能有空格+(group2: 1个以上数字)+可能有空格+'KB'+可能有空格+'D'\n",
    "            search_obj = re.match(r\"(\\d+)\\s*KB\\s*I\\s*\\+\\s*(\\d+)\\s*KB\\s*D\", x)\n",
    "            l1i_kb = int(int(search_obj.group(1)) * chips_num / float(cores_num))\n",
    "            l1d_kb = int(int(search_obj.group(2)) * chips_num / float(cores_num))\n",
    "            return f\"{l1i_kb}KB(I)+{l1d_kb}KB(D)\"\n",
    "    else:   #eg. 192 KB I on chip per chip, 96 KB I shared / 2 cores; 16 KB D on chip per core\n",
    "        search_obj = re.match(r\"(\\d+)\\s*KB\\s*I.*(\\d+)\\s*KB\\s*D\", x)\n",
    "        l1i_kb = int(int(search_obj.group(1)) * chips_num / float(cores_num))\n",
    "        l1d_kb = search_obj.group(2)\n",
    "        return f\"{l1i_kb}KB(I)+{l1d_kb}KB(D)\"\n",
    "\n",
    "\n",
    "# 4.2.7.2 2nd Cache\n",
    "def second_cache_rule(line: pd.Series) -> str:\n",
    "    \"\"\"\n",
    "    对2nd Cache这一列数据的处理操作，用于DataFrame的apply方法（需要用到其他属性的值）\n",
    "    :param line: DataFrame的一行，类型是pd.Series\n",
    "    :return: 处理后的2nd Cache per core(KB)值\n",
    "    \"\"\"\n",
    "    x = line[\"2nd Cache per core(KB)\"]\n",
    "    cores_num = line[\"# cores\"]\n",
    "    chips_num = line[\"# chips\"]\n",
    "    if x.find(\"I+D\") != -1:\n",
    "        if x.find(\"per core\") != -1:\n",
    "            if x.find(\"KB\") != -1:   # eg. 256 KB I+D on chip per core\n",
    "                search_obj = re.match(r\"(\\d+)\\s*KB\", x)\n",
    "                l2_kb = search_obj.group(1)\n",
    "                return f\"{l2_kb}KB(I+D)\"\n",
    "            else:  #eg. 1 MB I+D on chip per core\n",
    "                search_obj = re.match(r\"(\\d+(\\.\\d+)?)\\s*MB\", x)\n",
    "                l2_kb = int(float(search_obj.group(1)) * 1024)\n",
    "                return f\"{l2_kb}KB(I+D)\"\n",
    "        elif x.find(\"per two cores\") != -1:   #eg. 1 MB I+D on chip per two cores\n",
    "            search_obj = re.match(r\"(\\d+(\\.\\d+)?)\\s*MB\", x)\n",
    "            l2_kb = int(float(search_obj.group(1)) * 1024 / 2)\n",
    "            return f\"{l2_kb}KB(I+D)\"\n",
    "        elif x.find(\"per chip\") != -1:\n",
    "            if x.find(\"KB\") != -1:  # eg. 1920 KB I+D on chip per chip\n",
    "                search_obj = re.match(r\"(\\d+)\\s*KB\", x)\n",
    "                l2_kb = int(int(search_obj.group(1)) * chips_num / float(cores_num))\n",
    "                return f\"{l2_kb}KB(I+D)\"\n",
    "            else:  #eg. 11 MB I+D on chip per chip\n",
    "                search_obj = re.match(r\"\\s*(\\d+)\\s*MB\", x)\n",
    "                l2_kb = int(int(search_obj.group(1)) * 1024 * chips_num / float(cores_num))\n",
    "                return f\"{l2_kb}KB(I+D)\"\n",
    "    else:\n",
    "        if x.find(\"redacted\") != -1:\n",
    "            return \"0\"\n",
    "        else:\n",
    "            # 说明：(group1: 1个以上数字)+可能有空格+'KB'+可能有空格+I'+可能有空格+'+'+可能有空格+(group2: 1个以上数字)+可能有空格+'KB'+可能有空格+'D'\n",
    "            # eg. 2 MB I on chip per chip (256 KB / 4 cores); 4 MB D on chip per chip (256 KB / 2 cores)\n",
    "            if x.find(\"(\") != -1:\n",
    "                search_obj = re.match(r\"\\s*(\\d+)\\s*MB\\s*I.*(\\d+)\\s*MB\\s*D\", x)\n",
    "                l1i_kb = int(int(search_obj.group(1)) * 1024 * chips_num / float(cores_num))\n",
    "                l1d_kb = int(int(search_obj.group(2)) * 1024 * chips_num / float(cores_num))\n",
    "                return f\"{l1i_kb}KB(I)+{l1d_kb}KB(D)\"\n",
    "            else:\n",
    "                if x.find(\"MB\") != -1:  # eg. 1 MB I + 256 KB D on chip per core\n",
    "                    search_obj = re.match(r\"(\\d+)\\s*MB\\s*I\\s*\\+\\s*(\\d+)\\s*KB\\s*D\", x)\n",
    "                    l1i_kb = int(search_obj.group(1)) * 1024\n",
    "                    l1d_kb = search_obj.group(2)\n",
    "                    return f\"{l1i_kb}KB(I)+{l1d_kb}KB(D)\"\n",
    "                else:  # eg.  512 KB I + 256 KB D on chip per core\n",
    "                    search_obj = re.match(r\"(\\d+)\\s*KB\\s*I\\s*\\+\\s*(\\d+)\\s*KB\\s*D\", x)\n",
    "                    l1i_kb = search_obj.group(1)\n",
    "                    l1d_kb = search_obj.group(2)\n",
    "                    return f\"{l1i_kb}KB(I)+{l1d_kb}KB(D)\"\n",
    "\n",
    "\n",
    "# 4.2.7.3 3rd Cache\n",
    "def third_cache_rule(line: pd.Series) -> str:\n",
    "    \"\"\"\n",
    "    对3rd Cache这一列数据的处理操作，用于DataFrame的apply方法（需要用到其他属性的值）\n",
    "    :param line: DataFrame的一行，类型是pd.Series\n",
    "    :return: 处理后的3rd Cache per chip(MB)值\n",
    "    \"\"\"\n",
    "    x = line[\"3rd Cache per chip(MB)\"]\n",
    "    cores_num = line[\"# cores\"]\n",
    "    chips_num = line[\"# chips\"]\n",
    "    if x.find(\"I+D\") != -1:\n",
    "        if x.find(\"per core\") != -1:  # eg. 9 MB I+D on chip per core\n",
    "            search_obj = re.match(r\"(\\d+)\\s*MB\", x)\n",
    "            l2_mb = int(int(search_obj.group(1)) * cores_num / float(chips_num))\n",
    "            return f\"{l2_mb}MB\"\n",
    "        else:\n",
    "            if x.find(\"KB\") != -1:   # eg. 38400 KB I+D on chip per chip\n",
    "                search_obj = re.match(r\"(\\d+(\\.\\d+)?)\\s*KB\\s*I\\+D\", x)\n",
    "                l2_kb = int(int(search_obj.group(1)) / 1024.0)\n",
    "                return f\"{l2_kb}MB\"\n",
    "            else:  # eg. 40 MB I+D on chip per chip\n",
    "                search_obj = re.match(r\"(\\d+(\\.\\d+)?)\\s*MB\\s*I\\+D\", x)\n",
    "                l2_mb = search_obj.group(1)\n",
    "                return f\"{l2_mb}MB\"\n",
    "    else:\n",
    "        if x.find(\"redacted\") != -1:\n",
    "            return \"0\"\n",
    "        elif x.find(\"None\") != -1:\n",
    "            return \"0\"\n",
    "        else:\n",
    "            # 说明：(group1: 1个以上数字)+可能有空格+'MB'\n",
    "            search_obj = re.match(r\"(\\d+)\\s*MB\", x)\n",
    "            l1_mb = search_obj.group(1)\n",
    "            return f\"{l1_mb}MB\"\n",
    "\n",
    "\n",
    "# 4.2.7.4 other Cache\n",
    "def other_cache_rule(line: pd.Series) -> str:\n",
    "    \"\"\"\n",
    "    对other Cache这一列数据的处理操作，用于DataFrame的apply方法（需要用到其他属性的值）\n",
    "    :param line: DataFrame的一行，类型是pd.Series\n",
    "    :return: 处理后的other Cache per chip(MB)值\n",
    "    \"\"\"\n",
    "    x = line[\"Other Cache per chip(MB)\"]\n",
    "    chips_num = line[\"# chips\"]\n",
    "    if x.find(\"None\") != -1:\n",
    "        return \"0\"\n",
    "    elif x.find(\"system\") != -1: #eg. 60 GB I+D off chip per system\n",
    "        search_obj = re.match(r\"(\\d+(\\.\\d+)?)\\s*GB\\s*I\\+D\", x)\n",
    "        l2_mb = int(int(search_obj.group(1)) * 1024 / chips_num)\n",
    "        return f\"{l2_mb}MB\"\n",
    "    else:   # 16 MB I+D off chip per 8 DIMMs\n",
    "        search_obj = re.match(r\"(\\d+(\\.\\d+)?)\\s*MB\\s*I\\+D\", x)\n",
    "        l2_mb = search_obj.group(1)\n",
    "        return f\"{l2_mb}MB\"\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "#### 8. Memory属性\n",
    "\n",
    "数据单位统一为“GB”，即“XXGB”的格式，将其中单位为“MB”的化为“GB”，部分没有单位的，其单位视为“MB”。例如“4096MB”应当化为“4GB”，例如“262144”应当化为“256GB”"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "outputs": [],
   "source": [
    "# 4.2.8 Memory\n",
    "def memory_rule(x: str) -> str:\n",
    "    \"\"\"\n",
    "    对Memory这一列数据的处理操作，用于DataFrame的map方法\n",
    "    :param x: Memory属性的值\n",
    "    :return: 处理后的Memory(GB)值\n",
    "    \"\"\"\n",
    "    y = re.sub(r\"\\(.*\\)\", \"\", x)  # 删除括号中的内容\n",
    "    y = y.rstrip()  # 删除末尾的空格\n",
    "    if y.find(\"MB\") != -1:\n",
    "        search_obj = re.match(r\"(\\d+)\\s*MB\", y)\n",
    "        memory_gb = int(int(search_obj.group(1)) / 1024.0)\n",
    "        return f\"{memory_gb}GB\"\n",
    "    elif y.find(\"GB\") != -1:\n",
    "        search_obj = re.match(r\"(\\d+)\\s*GB\", y)\n",
    "        return f\"{search_obj.group(1)}GB\"\n",
    "    elif y.find(\"TB\") != -1:\n",
    "        search_obj = re.match(r\"(\\d+)\\s*TB\", y)\n",
    "        memory_gb = int(int(search_obj.group(1)) * 1024)\n",
    "        return f\"{memory_gb}GB\"\n",
    "    else:\n",
    "        return f\"{int(int(y) / 1024.0)}GB\"\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "#### 9. Updated属性：不处理\n",
    "\n",
    "#### 10. Disclosure属性\n",
    "\n",
    "给出了HTML和Text格式的报告链接，其中链接指向HTML的详细信息页面，将对应超链接的地址和“https://www.spec.org”拼接，得到对应完整链接，即\n",
    "\n",
    "\"<A HREF=\"\"/jvm2008/results/res2008q3/jvm2008-20080617-00001.html\"\">HTML</A> <A HREF=\"\"/jvm2008/results/res2008q3/jvm2008-20080617-00001.txt\"\">Text</A>\""
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "outputs": [],
   "source": [
    "# 4.2.10 Disclosure\n",
    "def report_link_rule(x: str) -> str:\n",
    "    \"\"\"\n",
    "    对Disclosure这一列数据的处理操作，用于DataFrame的map方法\n",
    "    :param x: Disclosure属性的值\n",
    "    :return: 处理后的Report Link值\n",
    "    \"\"\"\n",
    "    search_obj = re.match(r'<A HREF=\"(.*)\">HTML</A>',x)\n",
    "    return f\"https://www.spec.org{search_obj.group(1)}\""
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "markdown",
   "source": [
    "逐一应用上述方法"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "outputs": [
    {
     "data": {
      "text/plain": "             Company                                             System  \\\n0        ACTION S.A.  ACTINA SOLAR 110 S6 (Intel Xeon E3-1220 v3, 3....   \n1        ACTION S.A.  ACTINA SOLAR 202 S6 (Intel Xeon E5-2697 v3, 2....   \n2        ACTION S.A.           ACTINA SOLAR 205 S5 (Intel Xeon E5-2420)   \n3        ACTION S.A.           ACTINA SOLAR 210 X5 (Intel Xeon E5-2630)   \n4        ACTION S.A.  ACTINA SOLAR 210 X6 (Intel Xeon E5-2603 v4, 1....   \n...              ...                                                ...   \n48376  Wipro Limited                 Wipro NetPowerZ2243/NetPowerZ2243R   \n48377       YOYOtech              Fi7EPOWER MLK1610 (Intel Core i7-965)   \n48378          Yadro        Yadro Vesnin (2.92 GHz, 40 cores, RHEL 7.4)   \n48379          Yadro        Yadro Vesnin (3.32 GHz, 32 cores, RHEL 7.2)   \n48380            ZTE                 ATCA SBCR (Intel Xeon E5-2628L v2)   \n\n       Result  # cores                          Processor  CPU Speed(MHz)  \\\n0        58.7        4              Intel Xeon E3-1220 v3            3100   \n1        67.5       28              Intel Xeon E5-2697 v3            2600   \n2        35.8       12                 Intel Xeon E5-2420            1900   \n3        41.5       12                 Intel Xeon E5-2630            2300   \n4        35.4       12              Intel Xeon E5-2603 v4            1700   \n...       ...      ...                                ...             ...   \n48376   258.0       12                   Intel Xeon X5670            2933   \n48377    88.3        4  Intel Core i7-965 Extreme Edition            3733   \n48378     0.0       40                         IBM POWER8            2926   \n48379     0.0       32                         IBM POWER8            3325   \n48380   406.0       16             Intel Xeon E5-2628L v2            1900   \n\n      1st Cache per core(KB) 2nd Cache per core(KB) 3rd Cache per chip(MB)  \\\n0            32KB(I)+32KB(D)             256KB(I+D)                    8MB   \n1            32KB(I)+32KB(D)             256KB(I+D)                   35MB   \n2            32KB(I)+32KB(D)             256KB(I+D)                   15MB   \n3            32KB(I)+32KB(D)             256KB(I+D)                   15MB   \n4            32KB(I)+32KB(D)             256KB(I+D)                   15MB   \n...                      ...                    ...                    ...   \n48376        32KB(I)+32KB(D)             256KB(I+D)                   12MB   \n48377        32KB(I)+32KB(D)             256KB(I+D)                    8MB   \n48378        32KB(I)+64KB(D)             512KB(I+D)                   80MB   \n48379        32KB(I)+64KB(D)             512KB(I+D)                   64MB   \n48380        32KB(I)+32KB(D)             256KB(I+D)                   20MB   \n\n      Other Cache per chip(MB) Memory(GB)   Updated  \\\n0                            0       32GB  Dec-2015   \n1                            0      256GB  Dec-2015   \n2                            0       96GB  Jul-2014   \n3                            0      128GB  Jul-2014   \n4                            0      256GB  Nov-2016   \n...                        ...        ...       ...   \n48376                        0       96GB  Jul-2014   \n48377                        0        9GB  Jul-2014   \n48378                     16MB     4096GB  Mar-2018   \n48379                     16MB     8192GB  Mar-2018   \n48380                        0      128GB  Sep-2015   \n\n                                             Report Link  \n0      https://www.spec.org/cpu2006/results/res2015q4...  \n1      https://www.spec.org/cpu2006/results/res2015q4...  \n2      https://www.spec.org/cpu2006/results/res2012q4...  \n3      https://www.spec.org/cpu2006/results/res2012q4...  \n4      https://www.spec.org/cpu2006/results/res2016q4...  \n...                                                  ...  \n48376  https://www.spec.org/cpu2006/results/res2011q3...  \n48377  https://www.spec.org/cpu2006/results/res2009q1...  \n48378  https://www.spec.org/cpu2006/results/res2018q1...  \n48379  https://www.spec.org/cpu2006/results/res2018q1...  \n48380  https://www.spec.org/cpu2006/results/res2015q3...  \n\n[48381 rows x 13 columns]",
      "text/html": "<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>Company</th>\n      <th>System</th>\n      <th>Result</th>\n      <th># cores</th>\n      <th>Processor</th>\n      <th>CPU Speed(MHz)</th>\n      <th>1st Cache per core(KB)</th>\n      <th>2nd Cache per core(KB)</th>\n      <th>3rd Cache per chip(MB)</th>\n      <th>Other Cache per chip(MB)</th>\n      <th>Memory(GB)</th>\n      <th>Updated</th>\n      <th>Report Link</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>ACTION S.A.</td>\n      <td>ACTINA SOLAR 110 S6 (Intel Xeon E3-1220 v3, 3....</td>\n      <td>58.7</td>\n      <td>4</td>\n      <td>Intel Xeon E3-1220 v3</td>\n      <td>3100</td>\n      <td>32KB(I)+32KB(D)</td>\n      <td>256KB(I+D)</td>\n      <td>8MB</td>\n      <td>0</td>\n      <td>32GB</td>\n      <td>Dec-2015</td>\n      <td>https://www.spec.org/cpu2006/results/res2015q4...</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>ACTION S.A.</td>\n      <td>ACTINA SOLAR 202 S6 (Intel Xeon E5-2697 v3, 2....</td>\n      <td>67.5</td>\n      <td>28</td>\n      <td>Intel Xeon E5-2697 v3</td>\n      <td>2600</td>\n      <td>32KB(I)+32KB(D)</td>\n      <td>256KB(I+D)</td>\n      <td>35MB</td>\n      <td>0</td>\n      <td>256GB</td>\n      <td>Dec-2015</td>\n      <td>https://www.spec.org/cpu2006/results/res2015q4...</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>ACTION S.A.</td>\n      <td>ACTINA SOLAR 205 S5 (Intel Xeon E5-2420)</td>\n      <td>35.8</td>\n      <td>12</td>\n      <td>Intel Xeon E5-2420</td>\n      <td>1900</td>\n      <td>32KB(I)+32KB(D)</td>\n      <td>256KB(I+D)</td>\n      <td>15MB</td>\n      <td>0</td>\n      <td>96GB</td>\n      <td>Jul-2014</td>\n      <td>https://www.spec.org/cpu2006/results/res2012q4...</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>ACTION S.A.</td>\n      <td>ACTINA SOLAR 210 X5 (Intel Xeon E5-2630)</td>\n      <td>41.5</td>\n      <td>12</td>\n      <td>Intel Xeon E5-2630</td>\n      <td>2300</td>\n      <td>32KB(I)+32KB(D)</td>\n      <td>256KB(I+D)</td>\n      <td>15MB</td>\n      <td>0</td>\n      <td>128GB</td>\n      <td>Jul-2014</td>\n      <td>https://www.spec.org/cpu2006/results/res2012q4...</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>ACTION S.A.</td>\n      <td>ACTINA SOLAR 210 X6 (Intel Xeon E5-2603 v4, 1....</td>\n      <td>35.4</td>\n      <td>12</td>\n      <td>Intel Xeon E5-2603 v4</td>\n      <td>1700</td>\n      <td>32KB(I)+32KB(D)</td>\n      <td>256KB(I+D)</td>\n      <td>15MB</td>\n      <td>0</td>\n      <td>256GB</td>\n      <td>Nov-2016</td>\n      <td>https://www.spec.org/cpu2006/results/res2016q4...</td>\n    </tr>\n    <tr>\n      <th>...</th>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n      <td>...</td>\n    </tr>\n    <tr>\n      <th>48376</th>\n      <td>Wipro Limited</td>\n      <td>Wipro NetPowerZ2243/NetPowerZ2243R</td>\n      <td>258.0</td>\n      <td>12</td>\n      <td>Intel Xeon X5670</td>\n      <td>2933</td>\n      <td>32KB(I)+32KB(D)</td>\n      <td>256KB(I+D)</td>\n      <td>12MB</td>\n      <td>0</td>\n      <td>96GB</td>\n      <td>Jul-2014</td>\n      <td>https://www.spec.org/cpu2006/results/res2011q3...</td>\n    </tr>\n    <tr>\n      <th>48377</th>\n      <td>YOYOtech</td>\n      <td>Fi7EPOWER MLK1610 (Intel Core i7-965)</td>\n      <td>88.3</td>\n      <td>4</td>\n      <td>Intel Core i7-965 Extreme Edition</td>\n      <td>3733</td>\n      <td>32KB(I)+32KB(D)</td>\n      <td>256KB(I+D)</td>\n      <td>8MB</td>\n      <td>0</td>\n      <td>9GB</td>\n      <td>Jul-2014</td>\n      <td>https://www.spec.org/cpu2006/results/res2009q1...</td>\n    </tr>\n    <tr>\n      <th>48378</th>\n      <td>Yadro</td>\n      <td>Yadro Vesnin (2.92 GHz, 40 cores, RHEL 7.4)</td>\n      <td>0.0</td>\n      <td>40</td>\n      <td>IBM POWER8</td>\n      <td>2926</td>\n      <td>32KB(I)+64KB(D)</td>\n      <td>512KB(I+D)</td>\n      <td>80MB</td>\n      <td>16MB</td>\n      <td>4096GB</td>\n      <td>Mar-2018</td>\n      <td>https://www.spec.org/cpu2006/results/res2018q1...</td>\n    </tr>\n    <tr>\n      <th>48379</th>\n      <td>Yadro</td>\n      <td>Yadro Vesnin (3.32 GHz, 32 cores, RHEL 7.2)</td>\n      <td>0.0</td>\n      <td>32</td>\n      <td>IBM POWER8</td>\n      <td>3325</td>\n      <td>32KB(I)+64KB(D)</td>\n      <td>512KB(I+D)</td>\n      <td>64MB</td>\n      <td>16MB</td>\n      <td>8192GB</td>\n      <td>Mar-2018</td>\n      <td>https://www.spec.org/cpu2006/results/res2018q1...</td>\n    </tr>\n    <tr>\n      <th>48380</th>\n      <td>ZTE</td>\n      <td>ATCA SBCR (Intel Xeon E5-2628L v2)</td>\n      <td>406.0</td>\n      <td>16</td>\n      <td>Intel Xeon E5-2628L v2</td>\n      <td>1900</td>\n      <td>32KB(I)+32KB(D)</td>\n      <td>256KB(I+D)</td>\n      <td>20MB</td>\n      <td>0</td>\n      <td>128GB</td>\n      <td>Sep-2015</td>\n      <td>https://www.spec.org/cpu2006/results/res2015q3...</td>\n    </tr>\n  </tbody>\n</table>\n<p>48381 rows × 13 columns</p>\n</div>"
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 5\n",
    "ods_cpu2006_data[\"Company\"] = ods_cpu2006_data[\"Company\"].map(company_rule)\n",
    "# ods_cpu2006_data[\"Processor\"] = ods_cpu2006_data[\"Processor\"].map(processor_rule)\n",
    "# ods_cpu2006_data[\"CPU Speed(MHz)\"] = ods_cpu2006_data[\"CPU Speed(MHz)\"].map(cpu_speed_rule)\n",
    "ods_cpu2006_data[\"1st Cache per core(KB)\"] = ods_cpu2006_data.apply(first_cache_rule, axis=1)\n",
    "ods_cpu2006_data[\"2nd Cache per core(KB)\"] = ods_cpu2006_data.apply(second_cache_rule, axis=1)\n",
    "ods_cpu2006_data[\"3rd Cache per chip(MB)\"] = ods_cpu2006_data.apply(third_cache_rule, axis=1)\n",
    "ods_cpu2006_data[\"Other Cache per chip(MB)\"] = ods_cpu2006_data.apply(other_cache_rule, axis=1)\n",
    "ods_cpu2006_data[\"Memory(GB)\"] = ods_cpu2006_data[\"Memory(GB)\"].map(memory_rule)\n",
    "ods_cpu2006_data[\"Report Link\"] = ods_cpu2006_data[\"Report Link\"].map(report_link_rule)\n",
    "# ods_cpu2006_data = ods_cpu2006_data.drop(columns=[\"# cores per chip\", \"CPU Speed\", \"1st Cache\", \"2nd Cache\", \"Other Cache\", \"Memory\", \"Disclosure\"])\n",
    "\n",
    "ods_order = [\"Company\", \"System\", \"Result\", \"# cores\", \"Processor\", \"CPU Speed(MHz)\", \"1st Cache per core(KB)\",\n",
    "             \"2nd Cache per core(KB)\", \"3rd Cache per chip(MB)\", \"Other Cache per chip(MB)\", \"Memory(GB)\",\n",
    "             \"Updated\", \"Report Link\"]\n",
    "\n",
    "ods_cpu2006_data = ods_cpu2006_data[ods_order]\n",
    "\n",
    "ods_cpu2006_data.to_csv(r'ods_cpu2006_data.csv')\n",
    "ods_cpu2006_data\n",
    "# print(ods_cpu2006_data)\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}